package com.ruoyi.admin.controller;

import com.ruoyi.admin.domain.TbBusinessInfo;
import com.ruoyi.admin.domain.TbBusinessInfoVo;
import com.ruoyi.admin.service.ITbBusinessInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 业务需求Controller
 * 
 * @author ab
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/admin/business")
public class TbBusinessInfoController extends BaseController
{
    @Autowired
    private ITbBusinessInfoService tbBusinessInfoService;

    @Autowired
    private ISysConfigService configService;

    /**
     * 查询业务需求列表
     */
    @PreAuthorize("@ss.hasPermi('admin:business:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbBusinessInfo tbBusinessInfo)
    {
        startPage();
//        String pythonPath = configService.selectConfigByKey("env.python");
//        String wechatRuntimePath = configService.selectConfigByKey("env.wechat.runtime");
//        String wechatExePath = configService.selectConfigByKey("env.wechat.exe");
//        JSONArray call = WechatOcr.call("D:\\workspace\\auto_grad_sys\\ruoyi-common\\src\\main\\java\\com\\ruoyi\\common\\utils\\j2cpp\\img.png", pythonPath, wechatRuntimePath, wechatExePath);
        List<TbBusinessInfoVo> list = tbBusinessInfoService.selectTbBusinessInfoList(tbBusinessInfo);
        return getDataTable(list);
    }

    /**
     * 导出业务需求列表
     */
    @PreAuthorize("@ss.hasPermi('admin:business:export')")
    @Log(title = "业务需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbBusinessInfo tbBusinessInfo)
    {
        List<TbBusinessInfoVo> list = tbBusinessInfoService.selectTbBusinessInfoList(tbBusinessInfo);
        ExcelUtil<TbBusinessInfoVo> util = new ExcelUtil<>(TbBusinessInfoVo.class);
        util.exportExcel(response, list, "业务需求数据");
    }

    /**
     * 获取业务需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:business:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbBusinessInfoService.selectTbBusinessInfoById(id));
    }

    /**
     * 新增业务需求
     */
    @PreAuthorize("@ss.hasPermi('admin:business:add')")
    @Log(title = "业务需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbBusinessInfo tbBusinessInfo)
    {
        return toAjax(tbBusinessInfoService.insertTbBusinessInfo(tbBusinessInfo));
    }

    /**
     * 修改业务需求
     */
    @PreAuthorize("@ss.hasPermi('admin:business:edit')")
    @Log(title = "业务需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbBusinessInfo tbBusinessInfo)
    {
        return toAjax(tbBusinessInfoService.updateTbBusinessInfo(tbBusinessInfo));
    }

    /**
     * 删除业务需求
     */
    @PreAuthorize("@ss.hasPermi('admin:business:remove')")
    @Log(title = "业务需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbBusinessInfoService.deleteTbBusinessInfoByIds(ids));
    }
}
